<div class="ajaxLoading">
<img src='<?php echo $engineReturn['admin_template']?>css/images/loading.gif' width="50" align="middle" />
</div>
<div id="containerInsertForm" style="display:none">
<h2></h2> 
<a href='#' class='aNav' id='view_data_id'>View Data</a>
<form id="frmEngineInsert" name="frmEngineInsert" method="post" action="<?php echo $baseUrlSave;?><?php echo $otority;?>/engine/<?php echo $engineReturn['modulename'];?>/normal/insert/<?php echo $engineReturn['idEdit']."";?>" enctype="multipart/form-data">
<table class="table" width="100%">
<?php
//echo "<pre>";
//print_r($engineReturn);
$editTrue	= ($engineReturn['idEdit']!="")?true:false;
if(isset($engineReturn['msg']))
foreach($engineReturn['msg'] as $msg)
{
	echo "<div class='inlineMessage'><a href='#".$msg[1]."'>".$msg[0]."</a></div>";
}
foreach($engineReturn['field'] as $key=>$row)
{
	$value	=	$row['real_value'];
//	echo $value."<br>";
	echo "<tr>";
		echo "<td  width='25%'>".$row['text']."</td>";
		echo "<td>";
		switch($row['input'])
		{
			case "hidden":
				echo "Auto";
				if(!$editTrue && $key==0)$value="";
				echo "<input type='hidden' id='".$row['name']."' name='".$row['name']."' value='".$value."'>";
			break;
			case "text_primary":
				if($engineReturn['idEdit']=='')
				{
					echo "<input type='text' id='".$row['name']."' name='".$row['name']."' class='rejectInput engineInput' size='".$row['attr']['size']."' maxlength='".$row['attr']['maxlength']."' title='Input Text' value='".$value."'>";
					echo "<div id='ajax-text-primary-".$row['name']."' style='min-height:15px;'></div>";
						echo "<script type='text/javascript'>";
						echo "$(document).ready(function(){";
						echo "$('#".$row['name']."').checkPrimary({
						module_name 		: '".$row['name']."'
						, ajax_div_id		: 'ajax-text-primary-".$row['name']."'
						, url				: '".$baseUrlSave."admin/engine/".$engineReturn['modulename']."/ajax/text_primary/".$row['name']."/'});";
						echo "});";
						echo "</script>";
				}
				else
				{
					echo "<b>".$value."</b>";
					echo "<input type='hidden' id='".$row['name']."' name='".$row['name']."' value='".$value."'>";
				}
			break;
			case "text":
				if(!($row['edit']==false && ($editTrue)))
					echo "<input type='text' id='".$row['name']."' name='".$row['name']."' class='rejectInput engineInput ".(($row['attr']['maxlength']==10)?"datepicker":"")."' size='".$row['attr']['size']."' maxlength='".$row['attr']['maxlength']."' title='Input Text' value='".$value."'>";
				else
				{
					echo $value;
					echo "<input type='hidden' id='".$row['name']."' name='".$row['name']."' value='".$value."'>";
				}
			break;

/*			case "password":
				echo "<input type='password' id='".$row['name']."' name='".$row['name']."' class='rejectInput engineInput' size='".$row['attr']['size']."' maxlength='".$row['attr']['maxlength']."' title='Input Text' value='".$value."'>";
			break;
*/
			case "text_area":
				if(!($row['edit']==false && ($editTrue)))
					echo "<textarea id='".$row['name']."' name='".$row['name']."' class='rejectInput engineInput' cols='".$row['attr']['cols']."' rows='".$row['attr']['rows']."' title='Input Text'>".$value."</textarea>";
				else
				{
					echo $value;
					echo "<input type='hidden' id='".$row['name']."' name='".$row['name']."' value='".$value."'>";
				}
			break;
			case "text_area_plus_editor":
				if(!($row['edit']==false && ($editTrue)))
				{
					echo "<textarea id='".$row['name']."' name='".$row['name']."' class='rejectInput ckeditor editor1' cols='".$row['attr']['cols']."' rows='".$row['attr']['rows']."' title='Input Text'>".$value."</textarea>";
					echo "<script type='text/javascript'>";
					echo "
				CKEDITOR.replace( '".$row['name']."',
					{
						toolbar : 'Basic',
						uiColor : '#9AB8F3'
					})";
					echo "</script>";
				}
				else
				{
					echo $value;
					echo "<input type='hidden' id='".$row['name']."' name='".$row['name']."' value='".$value."'>";
				}
			break;
			case "password":
				echo "<input type='password' id='".$row['name']."' name='".$row['name']."' class='rejectInput engineInput' size='".$row['attr']['size']."' maxlength='".$row['attr']['maxlength']."' value=''>";
			break;
			case "radio":
				if(!($row['edit']==false && ($editTrue)))
				{
					if(is_array($value))
						$value = $value[0];
					echo "<table>";
					foreach($row['real_source'] as $rs)
					{
						echo "<tr><td>";
							echo "<input type='radio' id='".$row['name']."' name='".$row['name']."' value='".$rs[0]."' ".(($value==$rs[0])?"checked='checked'":"")."> ".(isset($rs[1])?$rs[1]:$rs[0]);
						echo "</td></tr>";
					}
					echo "</table>";
				}
				else
				{
					if(is_array($value))
						$value = $value[0];
					foreach($row['real_source'] as $rs)
						if($rs[0]==$value)
							echo isset($rs[1])?$rs[1]:$rs[0];
					echo "<div style='display:none;'>";
					echo "<table>";
					foreach($row['real_source'] as $rs)
					{
						echo "<tr><td>";
							echo "<input type='radio' id='".$row['name']."' name='".$row['name']."' value='".$rs[0]."' ".(($value==$rs[0])?"checked='checked'":"")."> ".(isset($rs[1])?$rs[1]:$rs[0]);
						echo "</td></tr>";
					}
					echo "</table>";
					echo "</div>";
				}
			break;
			case "checkbox":
				echo "<table>";
				foreach($row['real_source'] as $i=>$rs)
				{
					$checkV	= "";
					if(is_array($value))
					foreach($value as $v)
					{
						if($v==$rs[0])
						$checkV = "checked='checked'";
					}
					echo "<tr><td>";
						echo "<input ".$checkV." type='checkbox' id='input-".$row['name']."-".$i."' name='input-".$row['name']."-".$i."' value='".$rs[0]."'> ".(isset($rs[1])?$rs[1]:$rs[0]);
					echo "</td></tr>";
				}
				echo "</table>";
			break;
			case "select":
				if(!($row['edit']==false && ($editTrue)))
				{
					echo "<select id='".$row['name']."' name='".$row['name']."'>";
					echo "<option value=''>-".$row['text']."-</option>";
					foreach($row['real_source'] as $rs)
					{
							echo "<option value='".$rs[0]."' ".(($value==$rs[0])?"selected='selected'":"")."> ".(isset($rs[1])?$rs[1]:$rs[0])."</option>";
					}
					echo "</select>";
				}
				else
				{
					echo "<input type='hidden' id='".$row['name']."' name='".$row['name']."' value='".$value."'>";
					echo $value;
				}
			break;
			case "image":
				echo "<div>
						<input type='file' id='".$row['name']."' name='".$row['name']."' class='engineInput' size='".$row['attr']['size']."' title='Input Image'>
					</div>";
				if(isset($value[0]) && ($value[0]!=''))
				{
					echo "<div id='countainer-imageitem-".$row['name']."' id='countainer-imageitem-".$row['name']."' class='defContainerImage'>";
						echo "<img src='".$value[0]."'/>";
						echo "<br><input type='checkbox' ".(($value[2])?"checked='checked'":"")." id='input-image-".$row['name']."' name='input-image-".$row['name']."' value='input-image-".$row['name']."'> Delete Image";
					echo "</div>";
				}
			break;
			case "file":
				echo "<div>
						<input type='file' id='".$row['name']."' name='".$row['name']."' class='engineInput' size='".$row['attr']['size']."' title='Input File'>
					</div>";
				if(isset($value[0]) && ($value[0]!=''))
				{
						echo "<a href='".$value[0]."' target='_SELF'>DOWNLOAD</a>";
						echo "<br><input type='checkbox' ".(($value[2])?"checked='checked'":"")." id='input-file-".$row['name']."' name='input-file-".$row['name']."' value='input-image-".$row['name']."'> Delete Image";
				}
			break;
			case "simple_table":
				if(!($row['edit']==false && ($editTrue)))
				{
					echo "<select id='".$row['name']."' name='".$row['name']."'>";
					echo "<option value=''>-".$row['text']."-</option>";
					foreach($row['real_source'] as $rs)
					{
							echo "<option value='".$rs['idRec']."'".(($value==$rs['idRec'])?"selected='selected'":"")."> ".$rs['dataRec']."</option>";
					}
					echo "</select>";
				}
				else
				{
					foreach($row['real_source'] as $rs)
					{
							if($value==$rs['idRec'])
							{
								echo "<input type='hidden' id='".$row['name']."' name='".$row['name']."' value='".$value."'>";
								echo $rs['dataRec'];
							}
					}
				}
			break;
			case "medium_table":
					$valueRec	= "";
					if(is_array($value))
					{
						$valueId	= $value[0];
						$valueRec	= $value[1];
					}
					else
					{
						$valueId	= "";
					}
					echo "<input type='hidden' id='".$row['name']."' name='".$row['name']."' value='".$valueId."'>";
					echo "<div  id='container-".$row['name']."' name='container-".$row['name']."' class='engineInputContainer'>";
						echo "<div id='edit-".$row['name']."' name='edit-".$row['name']."' class='defContainer' title='Press here to switch beetwen Search and View Mode'>";
							echo "<a href='#' class='engineInputEdit' id='edit-button-".$row['name']."' name='edit-button-".$row['name']."'>Edit</a>";
						echo "</div>";

						echo "<div id='search-".$row['name']."' name='search-".$row['name']."' class='defContainer' style='display:none;'>";
							echo "<input type='text' id='search-input-".$row['name']."' name='search-input-".$row['name']."' class='rejectInput engineInput' size='' maxlength=''>";
							echo "<div id='ajax-".$row['name']."' name='ajax-".$row['name']."' class='containerAjax'></div>";
						echo "</div>";

						echo "<div  id='view-".$row['name']."' name='view-".$row['name']."' class='engineInputView'>";
							if(is_array($valueRec) && ($valueId))
							{
								echo "<table class='table'>";
									echo "<tr>";
									foreach($valueRec[1] as $v)
									{
										echo "<th>$v</th>";
									}
									echo "</tr>";
									echo "<tr>";
									foreach($valueRec[0][0] as $v)
									{
										echo "<td>$v</td>";
									}
									echo "</tr>";
								echo "</table>";
							}
						echo "</div>";
					echo "</div>";
					echo "<script type='text/javascript'>";
					echo "$(document).ready(function(){";
					echo "$('#edit-button-".$row['name']."').loadMediumTable({
					module_name 		: '".$row['name']."'
					, search_div_id 	: 'search-".$row['name']."'
					, search_input_id 	: 'search-input-".$row['name']."'
					, view_div_id		: 'view-".$row['name']."'
					, ajax_div_id		: 'ajax-".$row['name']."'
					, url				: '".$baseUrlSave.$otority."/engine/".$engineReturn['modulename']."/ajax/medium_table/".$row['name']."/'});";
					echo "});";
					echo "</script>";
			break;
			case "advance_table":
					$valueRec	= "";
//					echo "<pre>";
//					print_r($value);
					if(is_array($value))
					{
						$valueId	= $value[0];
						$valueRec	= $value[1];
					}
					else
					{
						$valueId	= "";
					}
					echo "<input type='hidden' id='".$row['name']."' name='".$row['name']."' value='".$valueId."'>";
					echo "<div  id='container-".$row['name']."' name='container-".$row['name']."' class='engineInputContainer'>";
						echo "<div id='edit-".$row['name']."' name='edit-".$row['name']."' class='defContainer'>";
							echo "<a href='#' class='engineInputEdit' id='edit-button-".$row['name']."' name='edit-button-".$row['name']."' title='Press here to switch beetwen Search and View Mode'>Edit</a>";
						echo "</div>";

						echo "<div id='search-".$row['name']."' name='search-".$row['name']."' class='defContainer' style='display:none;'>";
							echo "<input type='text' id='search-input-".$row['name']."' name='search-input-".$row['name']."' class='rejectInput engineInput' size='' maxlength=''>";
							if(is_array($row['real_source']))
							{
								echo "<div id='filter-".$row['name']."' name='filter-".$row['name']."' class='containerFilter'>";
								echo "<h3>Filter</h3>";
								echo "<table class='table'>";
								foreach($row['real_source'] as $k=>$r)
								{
									echo "<tr>";
									echo "<td><b>".$r['text']."</b></td>";
									echo "<td>";
									switch($r['input'])
									{
										case "text":
											echo "<input type='text' id='filter-id-".$k."' name='filter-id-".$k."' class='engineInput' size='30' maxlength='100'>";
										break;
										case "radio":
											echo "<table>";
											foreach($r['source'] as $rs)
											{
												echo "<tr><td>";
													echo "<input type='radio' id='filter-id-".$k."' name='filter-id-".$k."' value='".$rs[0]."'> ".(isset($rs[1])?$rs[1]:$rs[0]);
												echo "</td></tr>";
											}
											echo "</table>";
										break;
										case "select":
											echo "<select id='filter-id-".$k."' name='filter-id-".$k."'>";
											echo "<option value=''>-".$r['text']."-</option>";
											foreach($r['source'] as $rs)
											{
													echo "<option value='".$rs[0]."'> ".(isset($rs[1])?$rs[1]:$rs[0])."</option>";
											}
											echo "</select>";
										break;
										case "simple_table":
											echo "<select id='filter-id-".$k."' name='filter-id-".$k."'>";
											echo "<option value=''>-".$row['text']."-</option>";
											foreach($r['source'] as $rs)
											{
													echo "<option value='".$rs['idRec']."'> ".$rs['dataRec']."</option>";
											}
											echo "</select>";
										break;
									}
									echo "</td>";
								}
								echo "</table>";
								echo "</div>";
							}
							echo "<div id='ajax-".$row['name']."' name='ajax-".$row['name']."' class='containerAjax'></div>";
						echo "</div>";

						echo "<div  id='view-".$row['name']."' name='view-".$row['name']."' class='engineInputView'>";
							if(is_array($valueRec) && ($valueId))
							{
								echo "<table class='table'>";
									echo "<tr>";
									foreach($valueRec[1] as $v)
									{
										echo "<th>$v</th>";
									}
									echo "</tr>";
									echo "<tr>";
									foreach($valueRec[0][0] as $v)
									{
										echo "<td>$v</td>";
									}
									echo "</tr>";
								echo "</table>";
							}
						echo "</div>";
					echo "</div>";
					echo "<script type='text/javascript'>";
					echo "$(document).ready(function(){";
					echo "$('#edit-button-".$row['name']."').loadAdvanceTable({
					module_name 		: '".$row['name']."'
					, search_div_id 	: 'search-".$row['name']."'
					, search_input_id 	: 'search-input-".$row['name']."'
					, view_div_id		: 'view-".$row['name']."'
					, ajax_div_id		: 'ajax-".$row['name']."'
					, filter_div_id 	: 'filter-".$row['name']."'
					, filter_count		: '".count($row['real_source'])."'
					, url				: '".$baseUrlSave.$otority."/engine/".$engineReturn['modulename']."/ajax/advance_table/".$row['name']."/'});";
					echo "});";
					echo "</script>";
			break;
			case "multiple_value_table":
					echo "<div  id='container-".$row['name']."' name='container-".$row['name']."' class='engineInputContainer'>";
						echo "<div id='container-field-".$row['name']."' name='container-field-".$row['name']."' class='defContainer2'>";
							if(is_array($value)&&(count($value)))
							{
								foreach($value as $o=>$v)
								{
								if(is_array($v))
									$v = $v['dataRec'];
								echo "<div id='item-field-".$row['name']."-".$o."' name='item-field-".$row['name']."' class=''>";
									echo "<input type='text' value='".$v."' id='input-".$row['name']."-".$o."' name='input-".$row['name']."-".$o."' class='rejectInput engineInput' size='50' maxlength=''>";
									echo "<div id='ajax-".$row['name']."-".$o."' name='ajax-".$row['name']."' class='containerAjax'></div>";
								echo "</div>";
								}
							}
							else
							{
								echo "<div id='item-field-".$row['name']."-0' name='item-field-".$row['name']."' class=''>";
									echo "<input type='text' id='input-".$row['name']."-0' name='input-".$row['name']."-0' class='engineInput' size='50' maxlength=''>";
									echo "<div id='ajax-".$row['name']."-0' name='ajax-".$row['name']."' class='containerAjax'></div>";
								echo "</div>";
							}
							
						echo "</div>";
						echo "<div id='add-".$row['name']."' name='add-".$row['name']."' class='multiAddContainer'>";
							echo "<a href='#' class='button' id='add-button-".$row['name']."' name='edit-button-".$row['name']."' title='Press Here to add data'>Add More...</a>";
							echo " <a href='#' class='button' id='remove-button-".$row['name']."' name='remove-button-".$row['name']."' title='Press Here to add data'>Remove Last...</a>";
						echo "</div>";
					echo "</div>";
					echo "<script type='text/javascript'>";
					echo "$(document).ready(function(){";
					echo "$('#add-button-".$row['name']."').loadMultipleValue({
					module_name 			: '".$row['name']."'
					, remove_id				: 'remove-button-".$row['name']."'
					, ajax_id				: 'ajax-".$row['name']."'
					, item_div_id			: 'item-field-".$row['name']."'
					, item_field_id			: 'input-".$row['name']."'
					, container_field_id	: 'container-field-".$row['name']."'
					, url					: '".$baseUrlSave.$otority."/engine/".$engineReturn['modulename']."/ajax/multiple_value/".$row['name']."/'});";
					echo "});";
					echo "</script>";
			break;
			case "multiple_value_table_foreign":
					echo "<div  id='container-".$row['name']."' name='container-".$row['name']."' class='engineInputContainer'>";
						echo "<div id='container-field-".$row['name']."' name='container-field-".$row['name']."' class='defContainer2'>";
//							echo "<pre>";
//							print_r($value);
							if(is_array($value)&&(count($value)))
							{
								foreach($value as $o=>$v)
								{
								if(isset($v['dataRec']))
								{
									$v[1] = $v['dataRec'];
									$v[0] = $v['idRec'];
								}
								echo "<div id='item-field-".$row['name']."-".$o."' name='item-field-".$row['name']."' class=''>";
									echo "<input type='hidden' value='".$v[0]."' id='id-".$row['name']."-".$o."' name='id-".$row['name']."-".$o."'>";
									echo "<input type='text' value='".$v[1]."' id='input-".$row['name']."-".$o."' name='input-".$row['name']."-".$o."' class='rejectInput engineInput' size='50' maxlength=''>";
									echo "<div id='ajax-".$row['name']."-".$o."' name='ajax-".$row['name']."' class='containerAjax'></div>";
								echo "</div>";
								}
							}
							else
							{
								echo "<div id='item-field-".$row['name']."-0' name='item-field-".$row['name']."' class=''>";
									echo "<input type='hidden' id='id-".$row['name']."-0' name='id-".$row['name']."-0'>";
									echo "<input type='text' id='input-".$row['name']."-0' name='input-".$row['name']."-0' class='engineInput' size='50' maxlength=''>";
									echo "<div id='ajax-".$row['name']."-0' name='ajax-".$row['name']."' class='containerAjax'></div>";
								echo "</div>";
							}
							
						echo "</div>";
						echo "<div id='add-".$row['name']."' name='add-".$row['name']."' class='multiAddContainer'>";
							echo "<a href='#' class='button' id='add-button-".$row['name']."' name='edit-button-".$row['name']."' title='Press Here to add data'>Add More...</a>";
							echo " <a href='#' class='button' id='remove-button-".$row['name']."' name='remove-button-".$row['name']."' title='Press Here to add data'>Remove Last...</a>";
						echo "</div>";
					echo "</div>";
					echo "<script type='text/javascript'>";
					echo "$(document).ready(function(){";
					echo "$('#add-button-".$row['name']."').loadMultipleValueForeign({
					module_name 			: '".$row['name']."'
					, remove_id				: 'remove-button-".$row['name']."'
					, ajax_id				: 'ajax-".$row['name']."'
					, item_div_id			: 'item-field-".$row['name']."'
					, item_field_id			: 'id-".$row['name']."'
					, item_field_input		: 'input-".$row['name']."'
					, container_field_id	: 'container-field-".$row['name']."'
					, url					: '".$baseUrlSave.$otority."/engine/".$engineReturn['modulename']."/ajax/multiple_value_foreign/".$row['name']."/'});";
					echo "});";
					echo "</script>";
			break;
			case "multiple_value_image":
					echo "<div  id='container-".$row['name']."' name='container-".$row['name']."' class='engineInputContainer'>";
						echo "<div id='container-field-".$row['name']."' name='container-field-".$row['name']."' class='defContainer2'>";
							echo "<div id='item-field-".$row['name']."-0' name='item-field-".$row['name']."' class=''>";
								echo "<input type='file' id='input-".$row['name']."-0' name='input-".$row['name']."-0' class='engineInput' size='50' maxlength=''>";
								echo "<div id='ajax-".$row['name']."-0' name='ajax-".$row['name']."' class='containerAjax'></div>";
							echo "</div>";
						echo "</div>";
						echo "<div id='add-".$row['name']."' name='add-".$row['name']."' class='multiAddContainer'>";
							echo "<a href='#' class='button' id='add-button-".$row['name']."' name='edit-button-".$row['name']."' title='Press Here to add data'>Add More...</a>";
							echo " <a href='#' class='button' id='remove-button-".$row['name']."' name='remove-button-".$row['name']."' title='Press Here to add data'>Remove Last...</a>";
						echo "</div>";
					echo "</div>";

					if(isset($value[0]) && (is_array($value[0])))
					{
						foreach($value[0] as $id=>$data)
						{
							$checked = false;
							if(is_array($value[2]))
							foreach($value[2] as $v2)
							{
								if($v2==$data['idRec'])
									$checked = true;
							}
							echo "<div id='countainer-imageitem-".$row['name']."' id='countainer-imageitem-".$row['name']."' class='defContainerImage'>";
								echo "<img src='".$data['dataRec']."'/>";
								echo "<br><input type='checkbox' ".(($checked)?"checked='checked'":"")." id='input-multiple-image-".$row['name']."-".$id."' name='input-multiple-image-".$row['name']."-".$id."' value='".$data['idRec']."'> Delete Image";
							echo "</div>";
							
						}
					}

					echo "<script type='text/javascript'>";
					echo "$(document).ready(function(){";
					echo "$('#add-button-".$row['name']."').loadMultipleValueImage({
					module_name 			: '".$row['name']."'
					, remove_id				: 'remove-button-".$row['name']."'
					, ajax_id				: 'ajax-".$row['name']."'
					, item_div_id			: 'item-field-".$row['name']."'
					, item_field_id			: 'input-".$row['name']."'
					, container_field_id	: 'container-field-".$row['name']."'
					, url					: '".$baseUrlSave.$otority."/engine/".$engineReturn['modulename']."/ajax/multiple_value/".$row['name']."/'});";
					echo "});";
					echo "</script>";
			break;
		}
		if(is_array($row['note']))
		foreach($row['note'] as $r)
		{
			echo "<br />".$r;
		}
		echo "</td>";
	echo "</tr>";
}

?>
	<tr>
    	<td colspan="2">
        	<input type="hidden" id="init" name="init" value="save">
        	<input type="submit" value="Save" class="button" id="submitInsert">
			<script type='text/javascript'>
				$(document).ready(function(){
					$('#frmEngineInsert').submit(function(){
						if(!confirm("Are You sure?"))
							return false;
					});
				});
			</script>
        </td>
    </tr>
</table>
</form>
</div>
<script type="text/javascript">
	$('#containerInsertForm').delay(100).show('slow');
	$('#view_data_id').navigateToView({
		url 			: '<?php echo $baseUrlSave;?><?php echo $otority;?>/engine/<?php echo $engineReturn['modulename'] ?>/ajax/view/all/',
		div_form 		: 'containerInsertForm',
		div_loading 	: 'ajaxLoading',
	});
	
<?php
	if(($engineReturn['setting_insert']==false) && ($engineReturn['update_success']==true))
		echo "$('#view_data_id').click();";
	if(($engineReturn['setting_edit']==false) && ($engineReturn['update_success']==false))
		echo "$('#view_data_id').click();";
?>

	$('.rejectInput').each(function(){
		var $this = $(this);
		$this.keydown(function(c){
			switch(c.keyCode)
			{
//				case 191:
				case 222:
					return false;
				break;
			}
		});
	});
</script>